<!DOCTYPE html>
<html>
  <head>
    <% include global/meta.html %>
    <% include global/top-css.html %>
    <title>yuscms</title>
</head>
  <body>
   
        <!--main-->
        <main class="main" data-info="<%=admin.permission%>">
			
          <div class="ys-admin-pos c-a1a3aa">
            首页<span class="f-sum">></span><span class="c-565b6d">管理员列表</span><span class="f-sum">></span><span class="c-565b6d">更新</span>
          </div>
      
          <div class="ys-admin-tablist">
              <div class="ys-admin-tab-header row justify-content-b">
                  <p class="f-14 c-565b6d pl-8 pt-6"></p>
              </div>
      
              <div class="mr-10 ml-10" v-loading="loading">
                  <form @submit.prevent="checkForm" name="form">
                  <ul class="overflow-h pb-20">
                    
                    <li class="row pd-10 f-14">
                      <div class="col-hd">
                        <label class="label">用&nbsp;户&nbsp; 名</label>
                      </div>
                      
                      <div class="col-10">
                        <input type="text" name="admin_user" disabled="disabled" class="input" v-model="params.admin_user" />
                      </div>
                    </li>
                     
                    <li class="row  pd-10 f-14">
                      <div class="col-hd">
                        <label class="label">密　　码</label>
                      </div>
                      <div class="col-10">
                        <input type="text" name="admin_pass"  class="input" v-model="params.admin_pass" />
                      </div>
                    </li>
      
                    <li class="row  pd-10 f-14">
                      <div class="col-hd">
                        <label class="label">确认密码</label>
                      </div>
                      <div class="col-10">
                        <input type="text" name="admin_repeatpass" v-model="params.admin_repeatpass"  class="input" />
                      </div>
                    </li>
      
                    <li class="row pd-10 f-14">
                        <div class="col-hd">
                          <label class="label">等　　级</label>
                        </div>
                                          
                        <div class="col-10">
                          <div class="select flex row">
                            <select class="flex" name="level" v-model="params.level" >
                                <option v-for="item in level" :key="item.id" :value="item.id">{{item.level_name}}</option>
                            </select>
                          </div>
                        </div>
                    </li>
      
                    <li class="pd-10 mt-35">
                      <div class="col-hd">
                       &nbsp;&nbsp;&nbsp;&nbsp;
                      </div>
                      <div class="col-bd row ml-35">
                        <input name="send" class="btn btn-sure ml-35" type="submit" value="确定发布"/>
                        <input name="send" class="btn btn-reset ml-35" type="reset" value="重置"/>
                      </div>
                    </li>
                  </ul>
               </form>
              </div>
          </div>
        </main>
    
	<% include global/all-js.html %>
	<script>
		var vm = new Vue({
			el:'.main',
			data:{
        loading:true,
        level:[],
        params:{
          admin_user:'',
          admin_pass:'',
          admin_repeatpass:'',
          level:'',
          id:$m.getParams('id'),
        }
			},
			methods:{
			
   
        //管理员信息
        queryAdminById(){
        
        let _this = this;
        axios.get('/api/admin/queryById',{
          params:{id:_this.params.id}
        })
        .then((data)=>{
          let filterData = data.data;
          console.log('-->',filterData)
          if(filterData){
              _this.params.admin_user=filterData.data[0].admin_user;
              _this.params.level=filterData.data[0].level;
              _this.params.id = filterData.data[0].id;
              _this.loading = false;
          }
          // }else{
          //   location.href = '/admin/login'
          // }
        })
        .catch((error)=>{
          console.error(error);
        })
      },

      adminLevel(){
      
        let _this = this;
        axios.get('/api/admin/level').then((data)=>{
          let filterData = data.data;
          console.log('--1>',filterData)
          if(filterData){
            _this.level = filterData.data;
            _this.params.level = _this.level[0].id
          }
          // }else{
          //   location.href = '/admin/login'
          // }
        }).catch((error)=>{
            console.error(error)
        })
      },

      adminEdit(){
        let _this = this;
          axios.post('/api/admin/edit', _this.params)
          .then((data)=>{
            let filterData = data.data;
            console.log(filterData)
            if(filterData && filterData.data.affectedRows>=1){
              tips(_this,'修改成功！');
            }
            // }else{
            //   location.href = '/admin/login'
            // }
          })
          .catch((error)=>{
            console.error(error);
          });
      },


      checkForm:function(){
        var _this = this;
        if(!hasPermission('11')){
              tipsWarn(_this,'对不起,您没有操作权限^_^');
              return
          }
        var fm = document.form;


        if(_this.params.admin_pass == '' || _this.params.admin_pass.length<6){
          tipsWarn(_this,'密码不得为空且不能小于六位！');
          fm.admin_pass.focus();
          return false;
        }

        if(_this.params.admin_pass != _this.params.admin_repeatpass){
          tipsWarn(_this,'两次密码不一致！');
          fm.admin_repeatpass.focus();
          return false;
        }
        _this.adminEdit();
      }
   
  },

  created: function(){
    this.queryAdminById();
    this.adminLevel();
  },
  mounted:function(){ 
  }
		});
	</script>	
	</body>
</html>